package com.example.demo.auto.base;

import com.beiding.businessplatform.request.R;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import javax.persistence.EntityNotFoundException;

@RestControllerAdvice
public class CommonExceptionHandler {

    @ExceptionHandler(EntityNotFoundException.class)
    public R forEntityNotFoundException(EntityNotFoundException e) {
        e.printStackTrace();
        return R.error("实体未找到,请确定实体存在");
    }

    @ExceptionHandler(Exception.class)
    public R forAnyException(Exception e) {
        e.printStackTrace();
        String message = e.getMessage();
        if (message == null) {
            return R.error("未知异常");
        } else {
            return R.error(message);
        }
    }


}
